package com.arch.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator;

import java.io.IOException;

/**
 * @author pizhihui
 * @date 2024-06-03 09:11
 */
public class MkdirDemo {


    public static void main(String[] args) throws IOException {

        System.setProperty("HADOOP_USER_NAME", "biadmin");


        Configuration conf = new Configuration();
        conf.addResource("core-site.xml");
        conf.addResource("hdfs-site.xml");

        String pattern = "/tmp/data";


        Path globPath = new Path(pattern);
        FileSystem fs = globPath.getFileSystem(conf);


        // RemoteIterator<LocatedFileStatus> locatedFileStatusRemoteIterator = fs.listFiles(pattern, false);



        boolean res = fs.mkdirs(new Path(pattern));
        System.out.println("创建文件结果: " + res);

//        FileStatus[] stats = fs.globStatus(globPath);
//
//        for (FileStatus stat : stats) {
//            System.out.println(stat);
//        }


    }
}
